import {isObjectEmpty, mobileCheck} from "../common";
import {reactive} from "vue";
import Calendar from "uview-plus/libs/util/calendar";

export const personFormCheck = (formData) => {
    if (!isObjectEmpty(formData)) {
        return true;
    }

    if (!mobileCheck(formData.cellphone)) {
        uni.$u.toast('请输入正确手机号')
        return false;
    }
    if (!formData.user_name) {
        uni.$u.toast('请输入姓名')
        return false;
    }
    if (!formData.cellphone) {
        uni.$u.toast('请输入手机号')
        return false;
    }

    return true;
}

export const userFormCheck = (formData) => {
    if (!isObjectEmpty(formData)) {
        return true;
    }

    if (!mobileCheck(formData.cellphone)) {
        uni.$u.toast('请输入正确手机号')
        return false;
    }
    if (!formData.user_name) {
        uni.$u.toast('请输入经办人姓名')
        return false;
    }
    if (!formData.cellphone) {
        uni.$u.toast('请输入经办人手机号')
        return false;
    }
    if (!formData.company_name) {
        uni.$u.toast('请输入企业名称')
        return false;
    }

    return true;
}

export const transformSinger = (item, append) => {
    return {
		id_no: item.id_card,
        user_name: item.name,
        cellphone: item.cellphone,
        cellphone_secret: item.cellphone_secret,
        company_name: item.company_name || '',
        signer_user_type: item.signer_user_type,
        key_word: append.value || '',
    }
}

export const formSinger = (type, personForm, enterpriseForm) => {

    if (type == 1 && isObjectEmpty(personForm) && personFormCheck(personForm)) {
        personForm.signer_user_type = 'member';
        return personForm;
    }
    if (type == 2 && isObjectEmpty(enterpriseForm) && userFormCheck(enterpriseForm)) {
        enterpriseForm.signer_user_type = 'user';
        return enterpriseForm;
    }

    return false;
}

export const showDate = reactive({
    defaultVal: Number((new Date()).setMonth((new Date()).getMonth()+1)),
    showDatetime: false,
    showDateValue: null,
    cancel: () => {
        showDate.showDatetime = false;
    },
    confirm: (e) => {
        showDate.showDateValue = uni.$u.timeFormat(e.value, 'yyyy-mm-dd')
        showDate.cancel();
        showDate.init.callback(showDate.showDateValue);
    },

    init: {
        callback: function () {
        }
    }

});
